#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/28 8:41 PM
# @Author  : Mr.Dynasty
# @File    : multiplicationtable.py
# @Software: PyCharm
# @license : Copyright(C), Mr.Dynasty

def main():
    #for...in 乘法表
    #左下角
    for i in range(1, 10):
        for j in range(1, i + 1):
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
        print()
    print('*' * 150)

    # 左上角
    for i in range(9, 0, -1):
        for j in range(1, i + 1):
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
        print()
    print('*' * 150)

    #右下角
    for i in range(1, 10):
        for m in range(1, 10 - i):
            print('{0} {0} {0} {0} {0:<5}'.format(' '), end='')
        for j in range(1, i + 1):
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
        print()
    print('*' * 150)

    #右上角
    for i in range(9, 0, -1):
        for m in range(9 - i, 0, -1):
            print('{0} {0} {0} {0} {0:<5}'.format(' '), end='')
        for j in range(i, 0, -1):
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
        print()
    print('*' * 150)

    #while 乘法表
    # 左下角
    i = 1
    while i < 10:
        j = 1
        while j < i + 1:
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
            j += 1
        print()
        i += 1
    print('*' * 150)

    # 左上角
    i = 9
    while i > 0:
        j = 1
        while j < i + 1:
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
            j += 1
        print()
        i -= 1
    print('*' * 150)

    # 右下角
    i = 1
    while i < 10:
        m = 1
        while m < 10 - i:
            print('{0} {0} {0} {0} {0:<5}'.format(' '), end='')
            m += 1
        j = 1
        while j < i + 1:
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
            j += 1
        print()
        i += 1
    print('*' * 150)

    # 右上角
    i = 9
    while i > 0:
        m = 9 - i
        while m > 0:
            print('{0} {0} {0} {0} {0:<5}'.format(' '), end='')
            m -= 1
        j = i
        while j > 0:
            print('{0} * {1} = {2:<5}'.format(j, i, i * j), end='')
            j -= 1
        print()
        i -= 1

if __name__ == '__main__':
    main()
